package com.Test;

import com.entity.Emp;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author ：Fmc
 * @date ：Created in 2022/6/14 8:58
 * @description：
 * @modified By：
 * @version:
 */
public class Test {
    public static void main(String[] args) {
        /*try {
            Class<?> clazz1 = Class.forName("com.Test.Person");
            System.out.println(clazz1);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        //2、通过.class的方式获取class对象
        Class<Person> clazz2 = Person.class;
        System.out.println(clazz2);
        //3、通过对象的getClass方法获取
        Person person= new Person();
        Class<? extends Person> clazz3 = person.getClass();
        System.out.println(clazz3);*/

        /*Class clazz3 = Emp.class;
        try {
            Field field = clazz3.getField("name");
            System.out.println(field);
            Field[] fields = clazz3.getFields();
            for (Field field1 : fields) {
                System.out.println(field1.toString());
            }
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }*/
        /*try {
            Field field = clazz3.getDeclaredField("ename");
            System.out.println(field);
            Field[] fields = clazz3.getDeclaredFields();
            for (Field field1 : fields) {
                System.out.println(field1.toString());
            }
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }*/
        Class clazz4 = Person.class;
        Person person = new Person();
        try {
            Method method = clazz4.getMethod("clac", int.class, int.class, String.class);
            Object num = method.invoke(person,10,5,"加");
            System.out.println("加：" + num);
            Object num2 = method.invoke(person,10,5,"减");
            System.out.println("减：" + num2);
            Object num3 = method.invoke(person,10,5,"乘");
            System.out.println("乘：" + num3);
            Object num4 = method.invoke(person,10,5,"除");
            System.out.println("除：" + num4);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
